﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Admin_login : System.Web.UI.Page
{
    AccessDAO dao = new AccessDAO();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Session["userId"] = "";
            Session["userName"] = "";
            Session["pass"] = "";
            if (Request.QueryString["Action"] == "quit")
            {
                Session["Admin"] = "No";
                Response.Write("<script>window.close();</script>");
            }
        }
    }
    protected void ImageButton1_Click1(object sender, ImageClickEventArgs e)
    {
        string name = this.txtName.Text;
        string pass = this.txtPass.Text;
        
        string yzm = this.TextBox1.Text;
        string yzm1 = Session["CheckCode"].ToString();
        if (!name.Equals("") && !pass.Equals(""))
        {
            if (yzm.Equals(yzm1))
            {
                string sql = "select * from userInfo where name='"+name+"' and pass='"+pass+"'";
                DataSet ds = dao.getDs(sql);
                
                if (ds.Tables["message"].Rows.Count!=0)
                {
                    foreach (DataRow dr in ds.Tables["message"].Rows)
                    {
                        Session["userId"] = dr["id"].ToString();
                        Session["userName"] = dr["name"].ToString();
                        Session["pass"] = dr["pass"].ToString();
                    }
                    Session["Admin"] = "yes";
                    //Server.Transfer("Default.aspx");
                    Response.Write(" <script Language=Javascript>window.top.location=\"Default.aspx\"; </script>");
                }
                else
                {
                    this.TextBox1.Text = "";
                    this.txtName.Text = "";
                    RegisterStartupScript("check", "<script language='javascript'>alert('信息错误，登录失败！');</script>");
                }
            }
            else
            {
                this.TextBox1.Text = "";
                RegisterStartupScript("check", "<script language='javascript'>alert('验证码错误！');</script>");
            }
        }
        else
        {
            RegisterStartupScript("check", "<script language='javascript'>alert('请填写完整！');</script>");
        }
    }
}
